package com.skywolf.chem.manager.service.impl;

import com.skywolf.chem.common.sysconfig.pojo.vo.PageVO;
import com.skywolf.chem.manager.entity.PushMessage;
import com.skywolf.chem.manager.entity.PushMessageParam;
import com.skywolf.chem.manager.mapper.PushMessageMapper;
import com.skywolf.chem.manager.service.IPushMessageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 消息推送表 服务实现类
 * </p>
 *
 * @author
 * @since 2020-07-13
 */
@Service
public class PushMessageServiceImpl extends ServiceImpl<PushMessageMapper, PushMessage> implements IPushMessageService {

    @Autowired
    PushMessageMapper pushMessageMapper;

    @Override
    public PageVO<PushMessage> pushMsgListPage(PushMessageParam queryParam) {
        Long startNum = queryParam.getPageSize()*(queryParam.getPageNum()-1);
        Long endNum = queryParam.getPageSize();
        Integer count = pushMessageMapper.getPushPageCountManager(queryParam.getArticleTitle(),queryParam.getPushMsg(),queryParam.getPushTitle(),
                queryParam.getPushStatus(),queryParam.getStartTime(),queryParam.getEndTime());
        List<PushMessage> list = pushMessageMapper.getPushPageListManager(startNum,endNum,
                queryParam.getArticleTitle(),queryParam.getPushMsg(),queryParam.getPushTitle(),queryParam.getPushStatus(),queryParam.getStartTime(),queryParam.getEndTime());

        PageVO<PushMessage> pageVO = new PageVO<>();
        pageVO.setList(list);
        pageVO.setTotal(Long.valueOf(count));
        pageVO.setPageSize(queryParam.getPageSize());
        pageVO.setPageNum(queryParam.getPageNum());
        Long totalPage = (count/queryParam.getPageSize())+(count%queryParam.getPageSize()>0?1:0);
        if(totalPage.equals(0)){
            totalPage = queryParam.getPageNum();
        }
        pageVO.setPages(totalPage);
        return pageVO;
    }
}
